<?php

namespace app\admin\controller\order;

use app\admin\controller\Controller;
use app\admin\model\order\Mobile as MobileOrder;
use app\model\MobileNotifyAgent;

class Mobile extends Controller
{
    protected function initialize()
    {
        parent::initialize();
    }

    /**
     * 列表.
     */
    public function list()
    {
        $model = new MobileOrder();
        $data = input('post.');
        
        return $model->getList($data);
    }

    /**
     * 退款.
     */
    public function refund()
    {
        $model = new MobileOrder();
        $res = $model->refund(input('post.id'));
        if (false === $res) {
            return fail($model->getError());
        }

        return success('退款成功');
    }

    /**
     * 手动更改订单状态
     *
     * @prams
     * $ids     订单id
     * $status  状态：1充值成功 2充值失败
     */
    public function update()
    {
        $model = new MobileOrder();
        $data = input('post.');

        return $model->update($data);
    }

    /*
     * API 订单手动回调通知
     */
    public function manualNotify()
    {
        $model = new MobileOrder();
        $data = input('post.');

        $res = $model->manualNotify($data);
        if (false === $res) {
            return fail($model->getError());
        }

        return success('回调成功');
    }

    /**
     * 代理商接口回调信息
     * @return \think\response\Json
     */
    public function notifyInfo() {
        $data = input('post.');
        $model = new MobileNotifyAgent();
        $list = $model->notifyInfo($data);
        return success('操作成功', $list);
    }

    /**
     * 下单失败不再切换通道.
     */
    public function failNotChange()
    {
        $model = new MobileOrder();
        $data = input('post.');

        $res = $model->failNotChange($data);
        if (false === $res) {
            return fail($res);
        }

        return success('操作成功');
    }

    /**
     * 订单轮询记录
     */
    public function history()
    {
        $model = new MobileOrder();
        $id = input('id');

        $list = $model->history($id);
        if (false === $list) {
            return fail($model->getError());
        }

        return success('操作成功', $list);
    }
}
